package com.sky.controller.user;

import com.github.pagehelper.PageHelper;
import com.sky.context.BaseContext;
import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.entity.ShoppingCart;
import com.sky.mapper.OrderDetalsMapper;
import com.sky.mapper.OrderMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController("userOrderController")

@RequestMapping("user/order")
@Api("用户订单相关接口")


public class OrderController {
@Autowired
private OrderService orderService;
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private OrderDetalsMapper orderDetalsMapper;

    @PostMapping("/submit")
    public Result<OrderSubmitVO> sub(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
    OrderSubmitVO orderServices = orderService.submit(ordersSubmitDTO);
    return Result.success(orderServices);
    }
    /**
     * 订单支付
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
//        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
//        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
@GetMapping("/reminder/{id}")
@ApiOperation("客户催单")
    public Result reminder(@PathVariable("id") Long id){

              orderService.reminder(id);

                return Result.success();
    }

    @GetMapping("/historyOrders")
    @ApiOperation("查询历史订单")
    public Result<PageResult> HhistoryOrders(int page,int pageSize,Integer status){
        PageResult PS=orderService.pageQueryUser(page,pageSize,status);
        return Result.success(PS);
    }


    /**
     * 查看菜品的订单的详细界面
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查看订单想详情")
    public Result<OrderVO> orderDetail(@PathVariable("id")Long id){
        OrderVO o=orderService.getDetails(id);
        return Result.success(o);
    }

    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable("id")Long id){
        orderService.cancel(id);
        return Result.success();
    }


    /**
     * 再来一单
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetition(@PathVariable("id") Long id){
        orderService.repetition(id);
        return Result.success();
    }

}
